﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Web.Http;
using Newtonsoft.Json;
using Webapi.Models;

namespace Webapi.Controllers
{
    public class LicenceController : ApiController
    {
        /// <summary>
        /// 验证激活码 
        /// </summary>
        /// <param name="value"></param>
        public HttpResponseMessage Post([FromBody]LicenceModel value)
        {
            var proId = value.ProId;
            var code = value.LicenceCode;
            

            ResultModel rs = new ResultModel();

            try
            {
                using (EstateLicenceEntities db = new EstateLicenceEntities())
                {
                    var info = db.LicenceCode.FirstOrDefault(o => o.L_ProId == proId && o.L_Code == code && o.L_TimeUseful > DateTime.Now && o.L_State == 0);
                    if (info != null)
                    {
                        rs.State = 0;
                        rs.Msg = "ok";
                        rs.Data = new
                        {
                            vr = info.L_Remark
                        };
                    }

                }
            }
            catch (Exception ex)
            {
               
            }
            HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(JsonConvert.SerializeObject(rs), Encoding.GetEncoding("UTF-8")) };
            return result;
        }
    }
}
